package com.gaogzhen.juc.visibility;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j(topic = "c.Test03")
public class Test03 {
    static boolean run = true;
    static Object lock = new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            while (run) {
                synchronized (lock) {
                    // 循环体
                }
            }
        });
        log.debug("t线程开始运行...");
        t.start();
        TimeUnit.SECONDS.sleep(1);
        log.debug("线程t退出循环...");
        run = false;
    }
}
